<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('发货单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>发货单号：</label>
                                <input type="text" name="billNo"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status"  th:with="type=${@dict.getType('bill_status')}">
                                    <option value="">全部</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="goods:bill:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="goods:bill:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="goods:bill:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="goods:bill:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('goods:bill:edit')}]];
        var removeFlag = [[${@permission.hasPermi('goods:bill:remove')}]];
        var prefix = ctx + "goods/bill";
        var comboxList = [[${@dict.getType('bill_status')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "发货单",
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [{
                    checkbox: true
                },
                {
                    field: 'billNo',
                    title: '发货单号'
                },
                {
                    field: 'quantity',
                    title: '数量'
                },
                {
                    field: 'totalPrice',
                    title: '总价'
                },
                {
                    field: 'deptName',
                    title: '收货仓库'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter:function (value, row, index) {
                        return $.table.selectDictLabel(comboxList, value);
                    }
                },
                {
                    field: 'remark',
                    title: ''
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        //新建状态下，才可以修改。
                        if(row.status==1){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.billNo + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.billNo + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="batchAdd(\'' + row.billNo + '\')"><i class="fa"></i>货物明细</a> ');

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        initChildTable = function(index, row, $detail) {
            var prefixDownload=ctx + "common/download/resource?resource=";
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            var prefix = ctx + "goods/billHead";
            $(childTable).bootstrapTable({
                url: prefix + "/list",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    billNo: row.billNo
                },
                columns: [
                    {
                        field: 'styleNumber',
                        title: '款号'
                    },
                    {
                        field: 'imgPath',
                        title: '图片',
                        formatter: function(value, row, index) {
                            //console.log(row.imgPath)
                            if(row.imgPath==''||row.imgPath==null){
                                return '';
                            }else{
                                return $.table.imageView(prefixDownload+row.imgPath);
                            }
                        }
                    },
                    {
                        field: 'quantity',
                        title: '数量'
                    },
                    {
                        field: 'price',
                        title: '单价'
                    },
                    {
                        field: 'totalPrice',
                        title: '总价'
                    }
                ]
            });
        };

        //发货
        function audit(id,status){
            $.modal.confirm("确认要发货吗？", function() {
                var prefix = ctx + "goods/bill"
                var url=prefix+"/audit?id="+id+"&status=2";
                $.operate.save(url);
            });
        }

        //添加商品
        function batchAdd(billNo){
            var url = ctx + "goods/billHead?billNo="+billNo;
            console.log("url:"+url)
            $.modal.openTab("发货单明细",url);
        }

    </script>
</body>
</html>